﻿//======================================================================
//
//        Copyright : Zhengzhou Strawberry Computer Technology Co.,LTD.
//        All rights reserved
//        
//        Application:NFinal MVC framework
//        Filename :NList.cs
//        Description :数据库表对象类(同List.cs 服务于.net2.0)
//
//        created by Lucas at  2015-6-30`
//     
//        WebSite:http://www.nfinal.com
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Web;

namespace NFinal.DB
{
    public class NList<T> : System.Collections.Generic.List<T>
    {
        public static bool operator true(NList<T> list)
        {
            if (list != null && list.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static bool operator false(NList<T> list)
        {
            if (list != null && list.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public void WriteJson(System.IO.TextWriter tw)
        {
            if (this)
            {
                tw.Write("null");
            }
            else
            {
                tw.Write("[");
                bool isFirst = true;
                foreach (NFinal.DB.JsonInterface str in this)
                {
                    if (!isFirst)
                    {
                        tw.Write(",");
                    }
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    str.WriteJson(tw);
                }
                tw.Write("]");
            }
        }
        public string ToJson()
        {
            if (this)
            {
                System.IO.StringWriter tw = new System.IO.StringWriter();
                this.WriteJson(tw);
                string result = tw.ToString();
                tw.Close();
                return result;
            }
            else
            {
                return "null";
            }
        }
    }
}